package com.mdd.front.controller.yangyangLeadingEnterprise.index;

import com.mdd.common.aop.NotLogin;
import com.mdd.common.entity.yangyangLeadingEnterprise.TAppCorporateFinance;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.CommonParam;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.CorporateFinanceParam;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.CorporateFinanceRecordParam;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppCorporateFinanceApplicationRecordService;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppCorporateFinanceService;
import com.mdd.front.validate.yangyangLeadingEnterprise.TAppCorporateFinanceApplicationRecordCreateValidate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("api.index/corporateFinance")
@Api(tags = "app首页---企业融资")
public class TAppCorporateFinanceController {

    @Resource
    ITAppCorporateFinanceService appCorporateFinanceService;

    @Resource
    ITAppCorporateFinanceApplicationRecordService appCorporateFinanceApplicationRecordService;

    /**
     * 企业融资列表
     * @param param
     * @return
     */
    @NotLogin
    @PostMapping(value = "/selectList",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="企业融资列表")
    @ResponseBody
    public String selectList(@RequestBody CorporateFinanceParam param) {
        List<TAppCorporateFinance> selectList = appCorporateFinanceService.selectList(param);
        return JsonReturn.success().setListData(Optional.ofNullable(selectList).orElse(new ArrayList<>())).toJsonStr();
    }

    /**
     * 企业融资详情
     * @return
     */
    @NotLogin
    @PostMapping(value = "/selectById",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="企业融资详情")
    @ResponseBody
    public String selectById(@RequestBody CommonParam param, HttpServletRequest request) {
        Integer id = param.getId();
        if(id==null || id<1){
            return JsonReturn.fail("参数不能为空！",40001).toJsonStr();
        }
        TAppCorporateFinance appCorporateFinance=appCorporateFinanceService.selectById(id);
        return JsonReturn.success().put("appCorporateFinance",appCorporateFinance).toJsonStr();
    }

    /**
     * 企业融资申请记录新增
     * @param param
     * @return
     */
    @NotLogin
    @PostMapping(value = "/addCorporateFinanceApplicationRecord",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="企业融资申请记录新增")
    @ResponseBody
    public String addCorporateFinanceApplicationRecord(@RequestBody CorporateFinanceRecordParam param) {
        return appCorporateFinanceApplicationRecordService.addCorporateFinanceApplicationRecord(param);
    }



}
